package com.paic.mhis.hcpms.audit.web.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.paic.mhis.core.auth.biz.service.UserDetails;
import com.paic.mhis.hcpms.agreement.healthcareprovider.util.HttpProcessUtil;
import com.paic.mhis.hcpms.audit.biz.service.AuditProblemsService;
import com.paic.pafa.appclient.annotation.BizServicesProxy;
import com.paic.pafa.exceptions.BusinessException;

/**
 * 
 * @author EX-XIEQI001
 *
 */

@Controller
@RequestMapping("/auditProblemsCancel/")
public class AuditProblemsCancelController {

	@BizServicesProxy
	public AuditProblemsService auditProblemsService;

	/**
	 * 事件撤销功能
	 * 
	 * 
	 * @param request
	 * @return
	 * @throws IOException 
	 * @throws UnsupportedEncodingException 
	 */
	@RequestMapping(value = "auditProblemsCancel.do", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> auditProblemsCancel(HttpServletRequest request)
			throws BusinessException {
		String str = null;
		try {
			str = HttpProcessUtil.readRequestBody(request);
		} catch (UnsupportedEncodingException e) {
			throw new BusinessException("获取参数出错!请联系管理员");
		} catch (IOException e) {
			throw new BusinessException("获取参数出错!请联系管理员");
		}
		JSONObject transferJson = JSON.parseObject(str);
		String problemCode = transferJson.get("problemCode").toString();
		String problemStatus = transferJson.get("problemStatus").toString();
		transferJson.getJSONObject("");
		Map<String, Object> result = new HashMap<String, Object>();
		UserDetails user = (UserDetails) request.getSession().getAttribute(
				"user");
		String msg = "";
		if (!StringUtils.hasText(problemCode)) {
			msg += "事件号不能为空,";
		}
		if (!StringUtils.hasText(problemStatus)) {
			msg += "事件状态不能为空";
		}
		if (!StringUtils.hasText(msg)) {
			msg = auditProblemsService.auditProblemsCancel(problemCode,
					problemStatus, user);
			if (!StringUtils.hasText(msg)) {
				msg = "撤销成功";
				result.put("starts", "0");
			}
			result.put("msg", msg);
		} else {
			result.put("msg", msg);
		}

		return result;

	}
}
